{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "# 决策树解决回归问题"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn import datasets\n",
    "\n",
    "boston = datasets.load_boston()\n",
    "X = boston.data\n",
    "y = boston.target"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn.model_selection._split import train_test_split\n",
    "X_train, X_test, y_train, y_test = train_test_split(X,y,random_state=666)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Decision Tree Regressor"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "DecisionTreeRegressor(criterion='mse', max_depth=None, max_features=None,\n           max_leaf_nodes=None, min_impurity_decrease=0.0,\n           min_impurity_split=None, min_samples_leaf=1,\n           min_samples_split=2, min_weight_fraction_leaf=0.0,\n           presort=False, random_state=None, splitter='best')"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from sklearn.tree.tree import DecisionTreeRegressor\n",
    "\n",
    "dt_reg = DecisionTreeRegressor()\n",
    "dt_reg.fit(X_train, y_train)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "默认的参数下，效果不太好"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.57675277683796278"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dt_reg.score(X_test,y_test)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1.0"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 只记住了训练样本的特征，在训练样本上看效果满分，但泛化能力不行，显然是过拟合了\n",
    "dt_reg.score(X_train, y_train)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "绘制学习曲线"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn.metrics.scorer import mean_squared_error\n",
    "\n",
    "def plot_learning_curve(algo, X_train, X_test, y_train, y_test):\n",
    "    \"\"\"\n",
    "    绘制学习曲线\n",
    "    :param algo: 要使用的机器学习算法模型，例如LinearRegression的实例\n",
    "    :param X_train: \n",
    "    :param X_test: \n",
    "    :param y_train: \n",
    "    :param y_test: \n",
    "    :return: \n",
    "    \"\"\"\n",
    "    train_score = []    # 对训练数据集的预测结果(每一次增加样本后的结果均方误差)\n",
    "    test_score = []     # 对测试数据集的预测结果(每一次增加样本后的结果均方误差)\n",
    "    for i in range(1, len(X_train) + 1):\n",
    "        algo.fit(X_train[:i], y_train[:i])\n",
    "        \n",
    "        y_train_predict = algo.predict(X_train[:i])\n",
    "        train_score.append(mean_squared_error(y_train[:i],y_train_predict))\n",
    "        \n",
    "        y_test_predict = algo.predict(X_test)\n",
    "        test_score.append(mean_squared_error(y_test, y_test_predict))\n",
    "    plt.plot([i for i in range(1,len(X_train) + 1)], np.sqrt(train_score), label='train')\n",
    "    plt.plot([i for i in range(1,len(X_train) + 1)], np.sqrt(test_score), label='test')\n",
    "    plt.legend()\n",
    "    # plt.axis([0, len(X_train) + 1, 0, 4])\n",
    "    plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXQAAAD8CAYAAABn919SAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALE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eooihKRMj2kIuiKIrSQVTQFUVRIoIKuqIoSkRQQVcURYkIKuiKoigRQQVdURQlIqigK4qiRAQVdEVRlIjw/wEBYBn3B2KDNgAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x109565ac8>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plot_learning_curve(DecisionTreeRegressor(), X_train, X_test, y_train, y_test)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 调整下参数会是啥样？\n",
    "#### 使用网格搜索"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [],
   "source": [
    "param_grid = [\n",
    "    {\n",
    "        'max_depth':[i for i in range(2,10)],\n",
    "        'min_samples_split':[i for i in range(2,10)],\n",
    "        'min_samples_leaf':[i for i in range(1,10)]\n",
    "        # 'max_leaf_nodes':[i for i in range(2,50)]\n",
    "    }\n",
    "]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn.model_selection._search import GridSearchCV\n",
    "\n",
    "dt_reg_2 = DecisionTreeRegressor()\n",
    "grid_search = GridSearchCV(dt_reg_2, param_grid,n_jobs=-1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [],
   "source": [
    "%%time\n",
    "grid_search.fit(X_train,y_train)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
